package org.test;

import java.lang.reflect.Method;
import java.util.Scanner;

public class MainTest06 {
    public static void main(String[] args) throws Exception {
        Class<String> stringClass = String.class;
        Method substring = stringClass.getMethod("substring", int.class, int.class);
        Method indexOf = stringClass.getMethod("indexOf", int.class);
        Scanner scanner = new Scanner(System.in);
        String email = null;
        boolean flag = true;

        while (flag){
            try{
                System.out.println("请输入邮箱");
                email = scanner.next();
                int atIndex = (Integer) indexOf.invoke(email, '@');
                String prefix = (String) substring.invoke(email, 0, atIndex);
                System.out.println("邮箱账户名：" + prefix);
                flag = false;
            }catch (Exception e){
                System.out.println("请输入正确的邮箱");
            }
        }


    }
}
